package com.example.module_home.intro

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieDrawable
import com.example.module_home.R

class BordAdapter(private val introList: List<BordItem>) :
    RecyclerView.Adapter<BordAdapter.BordViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BordViewHolder {
        return BordViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.home_item_bord_container, parent, false)
        )
    }

    override fun getItemCount(): Int {
        return introList.size
    }

    override fun onBindViewHolder(holder: BordViewHolder, position: Int) {
        holder.bind(introList[position])
    }


    inner class BordViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        //private val imageView: ImageView = itemView.findViewById(R.id.img_bord)
        private val lottieView: LottieAnimationView = itemView.findViewById(R.id.lottie_view)
        private val tvTitle: TextView = itemView.findViewById(R.id.tv_title)
        private val tvDesc: TextView = itemView.findViewById(R.id.tv_date)

        fun bind(bordItem: BordItem?) {
            bordItem?.let {
                //imageView.setImageResource(it.bordImage)
                lottieView.apply {
                    setAnimation(bordItem.bordImage)
                    repeatMode = LottieDrawable.RESTART
                    repeatCount = LottieDrawable.INFINITE
                    playAnimation()
                }

                tvTitle.text = it.title
                tvDesc.text = it.desc
            }
        }
    }
}